package com.qdu.reducer;

import com.qdu.bean.bikeWritable;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class RentByTempReducer extends Reducer<DoubleWritable, bikeWritable,DoubleWritable,bikeWritable> {
     bikeWritable bw1=new bikeWritable();
    @Override
    protected void reduce(DoubleWritable key, Iterable<bikeWritable> values, Context context) throws IOException, InterruptedException {
        int casual=0;
        int registered=0;
        int count=0;
        int sum=0;
        for (bikeWritable b :
                values) {
            casual+=b.getCasual();
            registered+=b.getRegistered();
            count+=b.getCount();
            sum++;
        }
        bw1.set2(casual/sum,registered/sum,count/sum);
        context.write(key,bw1);
    }
}
